package main

import (
	"os"
	"qbl_spider/sconf"
	"qbl_spider/sflag"
	"qbl_spider/share"
	"qbl_spider/slog"
	spider2 "qbl_spider/spider"
	"qbl_spider/sredis"
)

/*
* @Auther:create by hjx
* @Email :1245863260@qq.com g1245863260@gmail.com
* @Date  :2021/4/5 19:11
 */
func init() {
	//init logger
	slog.SlogInit(sconf.LogName, sconf.LogPrefix)
}

func main() {
	defer slog.Slog.File.Close()
	sredis.RedisClient()
	defer sredis.RedisConn.Close()
	slog.Slog.Logger.Println(slog.Info, slog.LogBegin)
	share.CheckStringIsNil(*sflag.Url, *sflag.Path, *sflag.Merger)
	if *sflag.Page < 0 {
		slog.Slog.Logger.Println(slog.Error, "page lt 0,exit 2")
		os.Exit(2)
	}
	slog.Slog.Logger.Println(slog.Info, "args check ok")
	spider := spider2.SpiderNew(*sflag.Url, *sflag.Path, *sflag.Merger, *sflag.Page, *sflag.User, *sflag.IsSuren)
	if err := spider.DeployWorkDir(); err != nil {
		slog.Slog.Logger.Println(slog.Error, "Spider check work dir err,exit 2")
		os.Exit(2)
	}
	spider.SpiderMain()
	slog.Slog.Logger.Println(slog.Info, slog.LogEnd)
}
